﻿////using System;
////using System.Collections.Generic;
////using FT.Architecture.NHibernate.SessionManagement;
////using FT.Architecture.Queries;
////using NHibernate.Criterion;

////namespace FT.Architecture.NHibernate.Queries
////{
////    public class QueryOverExecutorService : IQueryExecutorService 
////    {
////         private readonly ISessionProviderService sessionProvider;

////        public QueryOverExecutorService(ISessionProviderService sessionProvider)
////        {
////            this.sessionProvider = sessionProvider;
////        }

////        public IEnumerable<T> Execute<T>(Query<T> query) where T : class
////        {
////            var session = sessionProvider.GetSession();

////            var queryOver = session.QueryOver<T>();

////            foreach (var c in query.Criteria)
////            {
////                ICriterion criterion;

////                switch (c.CriteriaOperator)
////                {
////                    case CriteriaOperator.Equal:
////                        criterion = Restrictions.Eq(c.PropertyName, c.Value);
////                        break;
////                    case CriteriaOperator.NotEqual:
////                        criterion = Restrictions.Not(Restrictions.Eq(c.PropertyName, c.Value));
////                        break;
////                    case CriteriaOperator.LessThanOrEqual:
////                        criterion = Restrictions.Le(c.PropertyName, c.Value);
////                        break;
////                    case CriteriaOperator.GreaterThanOrEqual:
////                        criterion = Restrictions.Ge(c.PropertyName, c.Value);
////                        break;
////                    case CriteriaOperator.GreaterThan:
////                        criterion = Restrictions.Gt(c.PropertyName, c.Value);
////                        break;
////                    case CriteriaOperator.LessThan:
////                        criterion = Restrictions.Lt(c.PropertyName, c.Value);
////                        break;
////                    case CriteriaOperator.Like:
////                        criterion = Restrictions.Like(c.PropertyName, c.Value + "%");
////                        break;
////                    case CriteriaOperator.SoundLike:
////                        criterion = new SQLCriterion("")
////                        break;
////                    case CriteriaOperator.IsNotNull:
////                        criterion = Restrictions.IsNotNull(c.PropertyName);
////                        break;
////                    case CriteriaOperator.IsNull:
////                        criterion = Restrictions.IsNull(c.PropertyName);
////                        break;
////                    default:
////                        throw new ApplicationException("No operator defined");
////                }

////                queryOver.Where(criterion);
////            }

////            foreach (var fetch in query.Fetches)
////            {
////                queryOver.Fetch(fetch.PropertyPath);
////            }

////            if (query.OrderByProperty.IsSet)
////            {
////                if (query.OrderByProperty.Descending)
////                {
////                    queryOver.OrderBy(query.OrderByProperty.PropertyPath).Desc();
////                }
////                else
////                {
////                    queryOver.OrderBy(query.OrderByProperty.PropertyPath).Asc();
////                }
////            }

////            return queryOver.List<T>();
////        }
////    }
////}
